Skip to content

Fix rescanning when a macro expansion result forms a new function-like macro call#682

Open
pfultz2 wants to merge 4 commits into
cppcheck-opensource:masterfrom
pfultz2:macro-expansion
Open

Fix rescanning when a macro expansion result forms a new function-like macro call#682
pfultz2 wants to merge 4 commits into
cppcheck-opensource:masterfrom
pfultz2:macro-expansion

Conversation

@pfultz2

@pfultz2 pfultz2 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

When the result of a macro expansion ends with the name of a function-like
macro and the tokens that follow supply its arguments, simplecpp performed
that rescan only once instead of repeatedly. Given:

#define a(b, c) c
#define d() a
#define g(e) h(e, ) h(e, )
#define h(e, b) d()(, e)()
#define i()
g(i)

g(i) expanded to i ( ) i ( ) instead of nothing: inside h's body
d()(, e)(), d() was correctly rescanned as a(, i) yielding i, but the
resulting i was never rescanned against the trailing ().

The rescan logic was also missing logic to prevent re-expanding the same macro name: so #define f() f + f()() gave f instead of f().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant